package com.example.demo.service.impl;

import com.example.demo.common.BaseMapper;
import com.example.demo.domain.dto.FindActiveUserReqDO;
import com.example.demo.domain.dto.FindActiveUserReqDTO;
import com.example.demo.domain.dto.FindActiveUserResqDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.demo.common.AbstractService;
import com.example.demo.dao.UserMapper;
import com.example.demo.domain.User;
import com.example.demo.service.UserService;

import java.util.List;
import java.util.Objects;

@Service
public class UserServiceImpl extends AbstractService<User> implements UserService {
    @Autowired
    private UserMapper userMapper;

    /**
     * 重写该方法,目的是为了覆盖超类中该方法的注解,指明注入指定的Mapper对象,否则spring
     * 无法确定注入哪个Mapper---有多个满足条件的Mapper.
     */
    @Override public BaseMapper<User> getMapper() {
        return userMapper;
    }

    @Override public FindActiveUserResqDTO findActiveUser(FindActiveUserReqDTO req) {
        FindActiveUserReqDO reqDO = new FindActiveUserReqDO();
        reqDO.setUsername(req.getUsername());
        reqDO.setEnabled(req.getEnabled());
        reqDO.setEmail(req.getEmail());
        reqDO.setQq(req.getQq());
        List<User> userList = userMapper.findActiveUser(reqDO);
        FindActiveUserResqDTO resp = new FindActiveUserResqDTO();
        if (Objects.isNull(userList)) {
            resp.setSuccess(false);
            resp.setMsg("user list is not exist!");
            return resp;
        }
        //
        resp.setSuccess(true);
        resp.setUserList(userList);
        return resp;
    }

    @Override public List<User> selectAll() {
        return userMapper.selectAll();
    }
}
